package cn.wenhe9.hefengweather.ui.place

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import cn.wenhe9.hefengweather.logic.Repository
import cn.wenhe9.hefengweather.logic.model.Location
import cn.wenhe9.hefengweather.logic.model.Place
import kotlin.collections.ArrayList

/**
 *@author DuJinliang
 *2021/10/1
 */
class PlaceViewModel : ViewModel() {
    private val searchLiveData = MutableLiveData<String>()

    val placeList = ArrayList<Location>()

    val placeLiveData = Transformations.switchMap(searchLiveData){ location ->
        Repository.searchPlace(location)
    }

    fun searchPlaces(location : String){
        searchLiveData.value = location
    }

    fun savePlace(place : Location) = Repository.savePlace(place)

    fun getSavedPlace() = Repository.getSavedPlace()

    fun isPlaceSaved() = Repository.isPlaceSaved()
}